import { API_PAY_ORDER } from '../sdk/business/url';
import getIn from '../sdk/utils/getIn';
export const PAY_FAIL = 'PAY_FAIL';
export function wxPay(params, callback) {
  global.request(API_PAY_ORDER, params, (status, result) => {
    if (status === 'SUCCESS') {
      wx.requestPayment({
        timeStamp: getIn(result, ['data', 'times']),
        nonceStr: getIn(result, ['data', 'nonce_str']),
        package: getIn(result, ['data', 'prepay_id']),
        signType: 'MD5',
        paySign: getIn(result, ['data', 'sign']),
        success(res) {
          callback('SUCCESS', res);
        },
        fail(res) {
          callback(PAY_FAIL, res);
        },
      });
    } else if (status === 'FAIL') {
      callback('FAIL', result);
    }
  });
}
